/*
 * Sessions.java
 *
 * Created on 12 wrzesie� 2007, 21:43
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package info.mikrotubula.db;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Entity class Sessions
 *
 * @author Krystian
 */
@Entity
@Table(name = "SESSIONS")
@NamedQueries( {
    @NamedQuery(name = "Sessions.findBySesId", query = "SELECT s FROM Sessions s WHERE s.sesId = :sesId"),
    @NamedQuery(name = "Sessions.findBySesDate", query = "SELECT s FROM Sessions s WHERE s.sesDate = :sesDate"),
    @NamedQuery(name = "Sessions.findByActive", query = "SELECT s FROM Sessions s WHERE s.sesAuth = :sesActive")
})
public class Sessions implements Serializable {
    
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name = "SES_ID", nullable = false)
    private Integer sesId;
    
    @Column(name = "SES_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date sesDate;
    
    @Column(name = "SES_AUTH")
    private boolean sesAuth;
    
    @Column(name = "SES_SEED")
    private Long sesSeed;
    
    @JoinColumn(name = "SES_USR_ID", referencedColumnName = "USR_ID")
    @ManyToOne
    private Users user;
    
    /** Creates a new instance of Sessions */
    public Sessions() {
        this.sesAuth = false;
        this.sesSeed = System.currentTimeMillis();
        this.sesDate = Calendar.getInstance().getTime();
    }
    
    /**
     * Creates a new instance of Sessions with the specified values.
     * @param sesId the sesId of the Sessions
     */
    public Sessions(Integer sesId) {
        this.sesId = sesId;
    }
   
    /**
     * Gets the sesId of this Sessions.
     * @return the sesId
     */
    public Integer getSesId() {
        return this.sesId;
    }
    
    /**
     * Sets the sesId of this Sessions to the specified value.
     * @param sesId the new sesId
     */
    public void setSesId(Integer sesId) {
        this.sesId = sesId;
    }
    
    /**
     * Gets the sesDate of this Sessions.
     * @return the sesDate
     */
    public Date getSesDate() {
        return this.sesDate;
    }
    
    /**
     * Sets the sesDate of this Sessions to the specified value.
     * @param sesDate the new sesDate
     */
    public void setSesDate(Date sesDate) {
        this.sesDate = sesDate;
    }

    /**
     * Returns a hash code value for the object.  This implementation computes
     * a hash code value based on the id fields in this object.
     * @return a hash code value for this object.
     */
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (this.sesId != null ? this.sesId.hashCode() : 0);
        return hash;
    }
    
    /**
     * Determines whether another object is equal to this Sessions.  The result is
     * <code>true</code> if and only if the argument is not null and is a Sessions object that
     * has the same id field values as this object.
     * @param object the reference object with which to compare
     * @return <code>true</code> if this object is the same as the argument;
     * <code>false</code> otherwise.
     */
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Sessions)) {
            return false;
        }
        Sessions other = (Sessions)object;
        if (this.sesId != other.sesId && (this.sesId == null || !this.sesId.equals(other.sesId))) return false;
        return true;
    }
    
    /**
     * Returns a string representation of the object.  This implementation constructs
     * that representation based on the id fields.
     * @return a string representation of the object.
     */
    @Override
    public String toString() {
        return "info.mikrotubula.db.Sessions[sesId=" + sesId + "]";
    }

    public Long getSesSeed() {
        return sesSeed;
    }

    public void setSesSeed(Long sesSeed) {
        this.sesSeed = sesSeed;
    }

    public boolean isSesAuth() {
        return sesAuth;
    }

    public void setSesAuth(boolean sesAuth) {
        this.sesAuth = sesAuth;
    }

    public Users getUser() {
        return user;
    }

    public void setUser(Users user) {
        this.user = user;
    }
    
}
